package com.alex.algorithm.iguide.dp;

public class JumpGame {


    public static void main(String[] args) {
        System.out.println(jumpToEndTimes(new int[]{3,2,3,5,6}));
    }

    public static int jumpToEndTimes(int[] arr) {
        if (arr == null || arr.length == 0){
            return 0;
        }
        int jump = 0;
        int cur = 0;
        int next = 0;
        for (int i = 0; i < arr.length; ++i) {
            if (cur < i) {
                ++jump;
                cur = next;
            }
            next = Math.max(i, i + arr[i]);
            System.out.println("i:" + i + ",jump:" + jump + ",cur:" + cur + ",next:" + next);
        }
        return jump;
    }
}
